home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Frameworks / TransSkel 3.24 / Documents / Tutorial / Examples / SimpleApp4.c < prev    next >
Text File  |  1996-01-17  |  2KB  |  122 lines

  1. # include   "TransSkel.h"
  2.  
  3.  
  4. static char lastChar = '\0';
  5. static Point lastLocation = { 20, 20 };
  6.  
  7.  
  8. static pascal void
  9. DoFileMenu (short item)
  10. {
  11.     SkelStopEventLoop ();            /* tell SkelEventLoop() to quit */
  12. }
  13.  
  14.  
  15. static pascal void
  16. Mouse (Point where, long when, short modifiers)
  17. {
  18. WindowPtr    w;
  19.  
  20.     lastLocation = where;
  21.     GetPort (&w);
  22.     InvalRect (&w->portRect);
  23. }
  24.  
  25.  
  26. static pascal void
  27. Key (short c, short code, short modifiers)
  28. {
  29. WindowPtr    w;
  30.  
  31.     lastChar = c;
  32.     GetPort (&w);
  33.     InvalRect (&w->portRect);
  34. }
  35.  
  36.  
  37. static pascal void
  38. Update (Boolean resized)
  39. {
  40. WindowPtr    w;
  41.  
  42.     GetPort (&w);
  43.     EraseRect (&w->portRect);
  44.     if (lastChar != '\0')
  45.     {
  46.         MoveTo (lastLocation.h, lastLocation.v);
  47.         DrawChar (lastChar);
  48.     }
  49.     DrawGrowIcon (w);
  50. }
  51.  
  52.  
  53. static pascal void
  54. Activate (Boolean active)
  55. {
  56. WindowPtr    w;
  57.  
  58.     GetPort (&w);
  59.     DrawGrowIcon (w);
  60. }
  61.  
  62.  
  63. static pascal void
  64. Close (void)
  65. {
  66.     SkelStopEventLoop ();
  67. }
  68.  
  69.  
  70. static pascal void
  71. Clobber (void)
  72. {
  73. WindowPtr    w;
  74.  
  75.     GetPort (&w);
  76.     DisposeWindow (w);
  77. }
  78.  
  79.  
  80. static pascal void
  81. Idle (void)
  82. {
  83. WindowPtr    w;
  84.  
  85.     GetPort (&w);
  86. }
  87.  
  88.  
  89. int
  90. main (void)
  91. {
  92. MenuHandle    m;
  93. WindowPtr    w;
  94. Rect        r;
  95.  
  96.     SkelInit (nil);                /* initialize */
  97.     SkelApple (nil, nil);        /* handle Apple menu */
  98.     /* create File menu, install handler */
  99.     m = NewMenu (skelAppleMenuID + 1, "\pFile");
  100.     AppendMenu (m, "\pQuit/Q");
  101.     (void) SkelMenu (m,                    /* menu handle */
  102.                         DoFileMenu,        /* item selection function */
  103.                         nil,            /* menu disposal function */
  104.                         false,            /* not a submenu */
  105.                         true);            /* draw menu bar */
  106.  
  107.     SetRect (&r, 40, 40, 200, 120);
  108.     w = NewWindow (nil, &r, "\pA Window", true,
  109.                         documentProc+8, (WindowPtr) -1, true, 0L);
  110.     (void) SkelWindow (w,
  111.                         Mouse,        /* mouse click handler */
  112.                         Key,        /* key click handler */
  113.                         Update,        /* update event handler */
  114.                         Activate,    /* activate event handler */
  115.                         Close,        /* close box click handler */
  116.                         Clobber,    /* disposal function */
  117.                         Idle,        /* idle-time handler */
  118.                         true);        /* idle only when frontmost */
  119.     SkelEventLoop ();
  120.     SkelCleanup ();
  121. }
  122.